package cn.com.huzo.repository.manufacture.impl;

import cn.com.huzo.model.entities.manufacture.RequisitionSlipHeaderEntity;
import cn.com.huzo.model.entities.manufacture.RequisitionSlipLinesEntity;
import cn.com.huzo.repository.manufacture.RequisitionSlipLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 领料单明细数据访问对象。
 *
 * @author 范学春
 */
@Repository("RequisitionSlipLinesRepository")
public class RequisitionSlipLinesRepositoryImpl extends GenericRepositoryImpl<RequisitionSlipLinesEntity, String>
        implements RequisitionSlipLinesRepository {

    private final String namespace = "cn.com.huzo.repository.manufacture.RequisitionSlipLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public RequisitionSlipLinesRepositoryImpl() {
        super(RequisitionSlipLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<RequisitionSlipLinesEntity> fetchByHeaderKey(Long headerKey) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderKey"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<RequisitionSlipLinesEntity> fetchLinesByProductColourForPrint(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchLinesByProductColourForPrint"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<RequisitionSlipLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(Long headerId, Long productId, Long userId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ProductId", productId);
        criterion.put("CreatedBy", userId);
        criterion.put("UpdatedBy", userId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(namespace,
                "insert"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer supplement(Long headerId, Long productId, Long userId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ProductId", productId);
        criterion.put("CreatedBy", userId);
        criterion.put("UpdatedBy", userId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(namespace,
                "supplement"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
